package com.example.orderfood2;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.orderfood2.DatabaseManager.DatabaseManager;
import com.example.orderfood2.RecyclerViewAdapter.RankAdapter;
import com.example.orderfood2.Repository.StudentRepository;
import com.example.orderfood2.Repository.TeacherRepository;
import com.example.orderfood2.entity.Student;
import com.example.orderfood2.util.DBUtil;

import java.util.List;

public class class_rank extends AppCompatActivity {
    private RecyclerView recyclerRankClass;
    private String science;
    private List<Student> class_rank;
    private StudentRepository dbUtil;
    private RankAdapter rankAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        dbUtil = DatabaseManager.getInstance(this).getStudentRepository();
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_class_rank);
//        dbUtil=new DBUtil(this);
        science=getIntent().getStringExtra("science");
        recyclerRankClass=findViewById(R.id.recyclerRankClass);
        //      作用是确定 RecyclerView 中各个列表项的排列方式为以线性列表的形式展示数据
        recyclerRankClass.setLayoutManager(new LinearLayoutManager(this));

        loadClassRank();
    }
    private void loadClassRank(){
        class_rank=dbUtil.getStudentsByScienceOrderByScoreDesc(science);
            rankAdapter = new RankAdapter(class_rank);
            recyclerRankClass.setAdapter(rankAdapter);

    }
}